direct = {

	North:(0,1),
	East:(1,0),
	West:(-1,0),
	South:(0,-1),
}

rev_direct = {
	North:South,
	East:West,
	West:East,
	South:North
}

def move_ntimes(dir, times):
	for _ in range(times):
		if not move(dir):
			return False
	return True
	
def min_dis_x(cur_x, x):
	if cur_x < x :
		if x - cur_x < get_world_size() + cur_x - x:
			return East, x - cur_x
		else:
			return West, cur_x - x + get_world_size()
	else:
		if cur_x - x < get_world_size() + x - cur_x:
			return West, cur_x - x
		else:
			return East, get_world_size() + x - cur_x
	
def dis_x(cur_x, x):
	if cur_x < x:
		return East, x - cur_x
	else:
		return West, cur_x - x
	
def dis_y(cur_y, y):
	if cur_y < y:
		return North, y - cur_y
	else:
		return South, cur_y - y

def min_dis_y(cur_y, y):
	if cur_y < y :
		if y - cur_y < get_world_size() + cur_y - y:
			return North, y - cur_y
		else:
			return South, cur_y - y + get_world_size()
	else:
		if cur_y - y < get_world_size() + y - cur_y:
			return South, cur_y - y
		else:
			return North, get_world_size() + y - cur_y

def move_to(x, y):
	cur_x = get_pos_x()
	cur_y = get_pos_y()
	dir, dis = min_dis_x(cur_x, x)
	move_ntimes(dir, dis)
	dir, dis = min_dis_y(cur_y, y)
	move_ntimes(dir, dis)

def try_move_to(x, y):
	cur_x = get_pos_x()
	cur_y = get_pos_y()
	dir, dis = dis_x(cur_x, x)
	if not move_ntimes(dir, dis):
		return False
	dir, dis = dis_y(cur_y, y)
	if not move_ntimes(dir, dis):
		return False
	return True
	
def move_in_square(x, y, len, f):
	move_to(x, y)
	while True:
		for i in range(len - 1):
			for j in range(len - 1):
				if f():
					return
				if get_pos_y() % 2 == 0:
					move(East)
				else:
					move(West)
			if f():
				return
			move(North)